<!DOCTYPE html>
<html class="client-nojs vector-feature-night-mode-disabled vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 vector-sticky-header-enabled" lang="en" dir="ltr"><head>
<meta charset="UTF-8">
<title>Null pointer</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="canonical" href="https://en.wikipedia.org/wiki/Null_pointer"> <link href="./mw/ext.cite.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/ext.pygments.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.icons.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.search.codex.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/user.styles.css" rel="stylesheet" type="text/css">
<meta name="ResourceLoaderDynamicStyles" content="">
<link rel="stylesheet" type="text/css" href="./mw/site.styles.css">
<link rel="stylesheet" type="text/css" href="./mw/noscript.css">
<link rel="stylesheet" type="text/css" href="./footer.css">
<link rel="stylesheet" type="text/css" href="./vector-2022.css">
</head>
<body class="skin--responsive skin-vector skin-vector-search-vue mediawiki ltr sitedir-ltr mw-hide-empty-elt ns-0 ns-subject page-Null_pointer rootpage-Null_pointer skin-vector-2022 action-view">
<div class="mw-page-container">
<div class="mw-page-container-inner">
<div class="mw-content-container">
<main id="content" class="mw-body">
<header class="mw-body-header vector-page-titlebar">
<h1 id="firstHeading" class="firstHeading mw-first-heading">
<span id="openzim-page-title" class="mw-page-title-main"><span class="mw-page-title-main">Null pointer</span></span>
</h1>
</header>
<a id="top"></a>
<div id="bodyContent" class="vector-body ve-init-mw-desktopArticleTarget-targetContainer" aria-labelledby="firstHeading" data-mw-ve-target-container="">
<div id="mw-content-text" class="mw-body-content mw-content-ltr" lang="en" dir="ltr"><div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr">
<p>In <a href="Computing" title="Computing">computing</a>, a <b>null pointer</b> (sometimes shortened to <b>nullptr</b> or <b>null</b>) or <b>null reference</b> is a value saved for indicating that the <a href="Pointer_(computer_programming)" title="Pointer (computer programming)">pointer</a> or <a href="Reference_(computer_science)" title="Reference (computer science)">reference</a> does not refer to a valid <a href="Object_(computer_science)" title="Object (computer science)">object</a>. Programs routinely use null pointers to represent conditions such as the end of a <a href="List_(computing)" class="mw-redirect" title="List (computing)">list</a> of unknown length or the failure to perform some action; this use of null pointers can be compared to <a href="Nullable_type" title="Nullable type">nullable types</a> and to the <i>Nothing</i> value in an <a href="Option_type" title="Option type">option type</a>.
</p><p>A null pointer should not be confused with an <a href="Uninitialized_variable" title="Uninitialized variable">uninitialized pointer</a>: a null pointer is guaranteed to compare unequal to any pointer that points to a valid object. However, in general, most languages do not offer such guarantee for uninitialized pointers. It might compare equal to other, valid pointers; or it might compare equal to null pointers. It might do both at different times; or the comparison might be <a href="Undefined_behavior" title="Undefined behavior">undefined behavior</a>. Also, in languages offering such support, the correct use depends on the individual experience of each developer and linter tools. Even when used properly, null pointers are <a href="Semantic_completeness" class="mw-redirect" title="Semantic completeness">semantically incomplete</a>, since they do not offer the possibility to express the difference between "not applicable", "not known", and "future" values.
</p><p>Because a null pointer does not point to a meaningful object, an attempt to access the data stored at that (invalid) memory location may cause a run-time error or immediate program crash. This is the <b>null pointer error</b>, or <b>null pointer exception</b>. It is one of the most common types of software weaknesses,<sup id="cite_ref-1" class="reference"><a href="#cite_note-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup> and <a href="Tony_Hoare" title="Tony Hoare">Tony Hoare</a>, who introduced the concept, has referred to it as a "billion dollar mistake".<sup id="cite_ref-:0_2-0" class="reference"><a href="#cite_note-:0-2"><span class="cite-bracket">[</span>2<span class="cite-bracket">]</span></a></sup>
</p>
<meta property="mw:PageProp/toc">
<div class="mw-heading mw-heading2"><h2 id="C">C</h2></div>
<p>In <a href="C_(programming_language)" title="C (programming language)">C</a>, two null pointers of any type are guaranteed to compare equal.<sup id="cite_ref-3" class="reference"><a href="#cite_note-3"><span class="cite-bracket">[</span>3<span class="cite-bracket">]</span></a></sup> Prior to C23, the preprocessor macro <code>NULL</code> was provided, defined as an implementation-defined null pointer constant in <code><<a href="Stdlib.h" class="mw-redirect" title="Stdlib.h">stdlib.h</a>></code>,<sup id="cite_ref-4" class="reference"><a href="#cite_note-4"><span class="cite-bracket">[</span>4<span class="cite-bracket">]</span></a></sup> which in <a href="C99" title="C99">C99</a> can be portably expressed as <code class="mw-highlight mw-highlight-lang-c mw-content-ltr" style="" dir="ltr"><span class="p">((</span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="p">)</span><span class="mi">0</span><span class="p">)</span></code>, the integer value <code>0</code> <a href="Type_conversion" title="Type conversion">converted</a> to the type <code>void*</code> (see <a href="Pointer_to_void_type" class="mw-redirect" title="Pointer to void type">pointer to void type</a>).<sup id="cite_ref-5" class="reference"><a href="#cite_note-5"><span class="cite-bracket">[</span>5<span class="cite-bracket">]</span></a></sup> Since <a href="C23_(C_standard_revision)" title="C23 (C standard revision)">C23</a>, a null pointer is represented with <code>nullptr</code> which is of type <code>nullptr_t</code> (originally introduced to C++11), providing a type safe null pointer.<sup id="cite_ref-N3042_6-0" class="reference"><a href="#cite_note-N3042-6"><span class="cite-bracket">[</span>6<span class="cite-bracket">]</span></a></sup>
</p><p>The C standard does not say that the null pointer is the same as the pointer to <a href="Memory_address" title="Memory address">memory address</a> 0, though that may be the case in practice. <a href="Dereferencing" class="mw-redirect" title="Dereferencing">Dereferencing</a> a null pointer is <a href="Undefined_behavior" title="Undefined behavior">undefined behavior</a> in C,<sup id="cite_ref-ub_7-0" class="reference"><a href="#cite_note-ub-7"><span class="cite-bracket">[</span>7<span class="cite-bracket">]</span></a></sup> and a conforming implementation is allowed to assume that any pointer that is dereferenced is not null.
</p><p>In practice, dereferencing a null pointer may result in an attempted read or write from <a href="Computer_memory" title="Computer memory">memory</a> that is not mapped, triggering a <a href="Segmentation_fault" title="Segmentation fault">segmentation fault</a> or memory access violation. This may manifest itself as a program crash, or be transformed into a software <a href="Exception_handling" title="Exception handling">exception</a> that can be caught by program code. There are, however, certain circumstances where this is not the case. For example, in <a href="Intel_x86" class="mw-redirect" title="Intel x86">x86</a> <a href="Real_mode" title="Real mode">real mode</a>, the address <code>0000:0000</code> is readable and also usually writable, and dereferencing a pointer to that address is a perfectly valid but typically unwanted action that may lead to undefined but non-crashing behavior in the application; if a null pointer is represented as a pointer to that address, dereferencing it will lead to that behavior. There are occasions when dereferencing a pointer to address zero <i>is</i> intentional and well-defined; for example, <a href="BIOS" title="BIOS">BIOS</a> code written in C for 16-bit real-mode x86 devices may write the <a href="Interrupt_descriptor_table" title="Interrupt descriptor table">interrupt descriptor table</a> (IDT) at physical address 0 of the machine by dereferencing a pointer with the same value as a null pointer for writing. It is also possible for the compiler to optimize away the null pointer dereference, avoiding a segmentation fault but causing other undesired behavior.<sup id="cite_ref-8" class="reference"><a href="#cite_note-8"><span class="cite-bracket">[</span>8<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-heading mw-heading2"><h2 id="C++">C++</h2></div>
<p>In C++, while the <code>NULL</code> macro was inherited from C, the integer literal for zero has been traditionally preferred to represent a null pointer constant.<sup id="cite_ref-9" class="reference"><a href="#cite_note-9"><span class="cite-bracket">[</span>9<span class="cite-bracket">]</span></a></sup> However, <a href="C%2B%2B11" title="C++11">C++11</a> introduced the explicit null pointer constant <code>nullptr</code> and type <code>nullptr_t</code> to be used instead, providing a type safe null pointer. <code>nullptr</code> and type <code>nullptr_t</code> were later introduced to C in C23.
</p>
<div class="mw-heading mw-heading2"><h2 id="Other_languages">Other languages</h2></div>
<p>In some programming language environments (at least one proprietary Lisp implementation, for example), the value used as the null pointer (called <code>nil</code> in <a href="Lisp_(programming_language)" title="Lisp (programming language)">Lisp</a>) may actually be a pointer to a block of internal data useful to the implementation (but not explicitly reachable from user programs), thus allowing the same register to be used as a useful constant and a quick way of accessing implementation internals. This is known as the <code>nil</code> vector.
</p><p>In languages with a <a href="Tagged_architecture" title="Tagged architecture">tagged architecture</a>, a possibly null pointer can be replaced with a <a href="Tagged_union" title="Tagged union">tagged union</a> which enforces explicit handling of the exceptional case; in fact, a possibly null pointer can be seen as a <a href="Tagged_pointer" title="Tagged pointer">tagged pointer</a> with a computed tag.
</p><p>Programming languages use different literals for the <i>null pointer</i>. In <a href="Python_(programming_language)" title="Python (programming language)">Python</a>, for example, a null value is called <code>None</code>. In <a href="Java_(programming_language)" title="Java (programming language)">Java</a> and <a href="C_Sharp_(programming_language)" title="C Sharp (programming language)">C#</a>, the literal <code>null</code> is provided as a literal for reference types. In <a href="Pascal_(programming_language)" title="Pascal (programming language)">Pascal</a> and <a href="Swift_(programming_language)" title="Swift (programming language)">Swift</a>, a null pointer is called <code>nil</code>. In <a href="Eiffel_(programming_language)" title="Eiffel (programming language)">Eiffel</a>, it is called a <code>void</code> reference.
</p>
<div class="mw-heading mw-heading2"><h2 id="Null_dereferencing">Null dereferencing</h2></div>
<p>Because a null pointer does not point to a meaningful object, an attempt to <a href="Dereference" class="mw-redirect" title="Dereference">dereference</a> (i.e., access the data stored at that memory location) a null pointer usually (but not always) causes a run-time error or immediate program crash. <a href="MITRE" class="mw-redirect" title="MITRE">MITRE</a> lists the null pointer error as one of the most commonly exploited software weaknesses.<sup id="cite_ref-10" class="reference"><a href="#cite_note-10"><span class="cite-bracket">[</span>10<span class="cite-bracket">]</span></a></sup>
</p>
<ul><li>In <a href="C_(programming_language)" title="C (programming language)">C</a>, dereferencing a null pointer is <a href="Undefined_behavior" title="Undefined behavior">undefined behavior</a>.<sup id="cite_ref-ub_7-1" class="reference"><a href="#cite_note-ub-7"><span class="cite-bracket">[</span>7<span class="cite-bracket">]</span></a></sup> Many implementations cause such code to result in the program being halted with an <a href="Access_violation" class="mw-redirect" title="Access violation">access violation</a>, because the null pointer representation is chosen to be an address that is never allocated by the system for storing objects. However, this behavior is not universal. It is also not guaranteed, since compilers are permitted to optimize programs under the assumption that they are free of undefined behavior. This behaviour is the same in <a href="C%2B%2B" title="C++">C++</a>, as there is no null pointer exception in the C++ language. On platforms such as <a href="Unix-like" title="Unix-like">Unix-like</a> systems and <a href="Windows" class="mw-redirect" title="Windows">Windows</a> with the <a href="Visual_Studio" title="Visual Studio">Visual Studio</a> compiler, an access violation causes a C/C++ <code><a href="SIGSEGV" class="mw-redirect" title="SIGSEGV">SIGSEGV</a></code> signal to be issued. Although in C/C++ null dereferences are not exceptions which can be caught in C++ <code>try</code>/<code>catch</code> blocks, it is possible to "catch" such an access violation by using (<code>std::</code>)<code>signal()</code> in C/C++ to specify a handler to be called when that signal is issued.</li>
<li>In <a href="D_(programming_language)" title="D (programming language)">D</a>, much like C++, a null pointer dereference results in a segmentation fault.</li>
<li>In <a href="Delphi_(programming_language)" class="mw-redirect" title="Delphi (programming language)">Delphi</a> and many other Pascal implementations, the constant <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">nil</code> represents a null pointer to the first address in memory which is also used to initialize managed variables. Dereferencing it raises an external OS exception which is mapped onto a Pascal <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">EAccessViolation</code> exception instance if the <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">System.SysUtils</code> unit is linked in the <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">uses</code> clause.</li>
<li>In <a href="Java_(programming_language)" title="Java (programming language)">Java</a>, access to a null reference (<code>null</code>) causes a <code><a rel="nofollow" class="external text" href="https://docs.oracle.com/en/java/javase/24/docs/api/java.base/java/lang/NullPointerException.html">NullPointerException</a></code> (NPE), which can be caught by error handling code, but the preferred practice is to ensure that such exceptions never occur.</li>
<li>In <a href="Lisp_(programming_language)" title="Lisp (programming language)">Lisp</a>, <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">nil</code> is a <a href="First_class_object" class="mw-redirect" title="First class object">first class object</a>. By convention, <code>(first nil)</code> is <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">nil</code>, as is <code>(rest nil)</code>. So dereferencing <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">nil</code> in these contexts will not cause an error, but poorly written code can get into an infinite loop.</li>
<li>In <a href=".Net_(programming_language)" class="mw-redirect" title=".Net (programming language)">.NET</a> and <a href="C_Sharp_(programming_language)" title="C Sharp (programming language)">C#</a>, access to null reference (<code>null</code>) causes a <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">NullReferenceException</code> to be thrown. Although catching these is generally considered bad practice, this exception type can be caught and handled by the program.</li>
<li>In <a href="Objective-C" title="Objective-C">Objective-C</a>, messages may be sent to a <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">nil</code> object (which is a null pointer) without causing the program to be interrupted; the message is simply ignored, and the return value (if any) is <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">nil</code> or <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">0</code>, depending on the type.<sup id="cite_ref-11" class="reference"><a href="#cite_note-11"><span class="cite-bracket">[</span>11<span class="cite-bracket">]</span></a></sup></li>
<li>In <a href="Python_(programming_language)" title="Python (programming language)">Python</a>, dereferencing <code>None</code> raises an <code>AttributeError</code>, as <code>NoneType</code> has no (user-facing) methods or attributes defined.</li>
<li>In <a href="Rust_(programming_language)" title="Rust (programming language)">Rust</a>, dereferencing a null pointer (<code>std::ptr::null()</code>) in an <code>unsafe</code> block results in undefined behaviour, which usually results in a segmentation fault or corrupted memory.</li>
<li>Before the introduction of <a href="Supervisor_Mode_Access_Prevention" title="Supervisor Mode Access Prevention">Supervisor Mode Access Prevention</a> (SMAP), a null pointer dereference bug could be exploited by mapping <a href="Zero_page" title="Zero page">page zero</a> into the attacker's <a href="Address_space" title="Address space">address space</a> and hence causing the null pointer to point to that region. This could lead to <a href="Arbitrary_code_execution" title="Arbitrary code execution">code execution</a> in some cases.<sup id="cite_ref-12" class="reference"><a href="#cite_note-12"><span class="cite-bracket">[</span>12<span class="cite-bracket">]</span></a></sup></li></ul>
<div class="mw-heading mw-heading2"><h2 id="Mitigation">Mitigation</h2></div>
<p>While there could be languages with no nulls, most do have the possibility of nulls so there are techniques to avoid or aid debugging null pointer dereferences.<sup id="cite_ref-BondNethercote2007_13-0" class="reference"><a href="#cite_note-BondNethercote2007-13"><span class="cite-bracket">[</span>13<span class="cite-bracket">]</span></a></sup> Bond et al.<sup id="cite_ref-BondNethercote2007_13-1" class="reference"><a href="#cite_note-BondNethercote2007-13"><span class="cite-bracket">[</span>13<span class="cite-bracket">]</span></a></sup> suggest modifying the Java Virtual Machine (JVM) to keep track of null propagation.
</p><p>There are three levels of handling null references, in order of effectiveness:
</p>
<ol><li>languages with no null;</li>
<li>languages that can statically analyse code to avoid the possibility of null dereference at run time;</li>
<li>if null dereference can occur at runtime, tools that aid debugging.</li></ol>
<p>Pure <a href="Functional_languages" class="mw-redirect" title="Functional languages">functional languages</a> are an example of level 1 since no direct access is provided to pointers and all code and data is immutable. User code running in <a href="Interpreter_(computing)" title="Interpreter (computing)">interpreted</a> or virtual-machine languages generally does not suffer the problem of null pointer dereferencing.
</p><p>Where a language does provide or utilise pointers which could become void, it is possible to avoid runtime null dereferences by providing <a href="Void_safety" title="Void safety">compilation-time checking</a> via <a href="Static_analysis" title="Static analysis">static analysis</a> or other techniques, with syntactic assistance from language features such as those seen in the <a href="Eiffel_programming_language" class="mw-redirect" title="Eiffel programming language">Eiffel programming language</a> with Void safety<sup id="cite_ref-14" class="reference"><a href="#cite_note-14"><span class="cite-bracket">[</span>14<span class="cite-bracket">]</span></a></sup> to avoid null dereferences, <a href="D_programming_language" class="mw-redirect" title="D programming language">D</a>,<sup id="cite_ref-SafeD_15-0" class="reference"><a href="#cite_note-SafeD-15"><span class="cite-bracket">[</span>15<span class="cite-bracket">]</span></a></sup> and <a href="Rust_programming_language" class="mw-redirect" title="Rust programming language">Rust</a>.<sup id="cite_ref-16" class="reference"><a href="#cite_note-16"><span class="cite-bracket">[</span>16<span class="cite-bracket">]</span></a></sup>
</p><p>In some languages analysis can be performed using external tools, but these are weak compared to direct language support with compiler checks since they are limited by the language definition itself.
</p><p>The last resort of level 3 is when a null reference occurs at runtime, debugging aids can help.
</p>
<div class="mw-heading mw-heading2"><h2 id="History">History</h2></div>
<p>In 2009, <a href="Tony_Hoare" title="Tony Hoare">Tony Hoare</a> stated<sup id="cite_ref-:0_2-1" class="reference"><a href="#cite_note-:0-2"><span class="cite-bracket">[</span>2<span class="cite-bracket">]</span></a></sup><sup id="cite_ref-17" class="reference"><a href="#cite_note-17"><span class="cite-bracket">[</span>17<span class="cite-bracket">]</span></a></sup>
<sup id="cite_ref-18" class="reference"><a href="#cite_note-18"><span class="cite-bracket">[</span>18<span class="cite-bracket">]</span></a></sup>
that he invented the null reference in 1965 as part of the <a href="ALGOL_W" title="ALGOL W">ALGOL W</a> language. In that 2009 reference Hoare describes his invention as a "billion-dollar mistake":
</p>
<style data-mw-deduplicate="TemplateStyles:r1244412712">
/* start https://en.wikipedia.org/ */
.mw-parser-output .templatequote{overflow:hidden;margin:1em 0;padding:0 32px}.mw-parser-output .templatequotecite{line-height:1.5em;text-align:left;margin-top:0}@media(min-width:500px){.mw-parser-output .templatequotecite{padding-left:1.6em}}
/* end https://en.wikipedia.org/ */
</style><blockquote class="templatequote"><p>I call it my billion-dollar mistake. It was the invention of the null reference in 1965. At that time, I was designing the first comprehensive type system for references in an object oriented language (ALGOL W). My goal was to ensure that all use of references should be absolutely safe, with checking performed automatically by the compiler. But I couldn't resist the temptation to put in a null reference, simply because it was so easy to implement. This has led to innumerable errors, vulnerabilities, and system crashes, which have probably caused a billion dollars of pain and damage in the last forty years.</p></blockquote>
<div class="mw-heading mw-heading2"><h2 id="See_also">See also</h2></div>
<ul><li><a href="Memory_debugger" title="Memory debugger">Memory debugger</a></li>
<li><a href="Zero_page" title="Zero page">Zero page</a></li></ul>
<div class="mw-heading mw-heading2"><h2 id="Notes">Notes</h2></div>
<style data-mw-deduplicate="TemplateStyles:r1239543626">
/* start https://en.wikipedia.org/ */
.mw-parser-output .reflist{margin-bottom:0.5em;list-style-type:decimal}@media screen{.mw-parser-output .reflist{font-size:90%}}.mw-parser-output .reflist .references{font-size:100%;margin-bottom:0;list-style-type:inherit}.mw-parser-output .reflist-columns-2{column-width:30em}.mw-parser-output .reflist-columns-3{column-width:25em}.mw-parser-output .reflist-columns{margin-top:0.3em}.mw-parser-output .reflist-columns ol{margin-top:0}.mw-parser-output .reflist-columns li{page-break-inside:avoid;break-inside:avoid-column}.mw-parser-output .reflist-upper-alpha{list-style-type:upper-alpha}.mw-parser-output .reflist-upper-roman{list-style-type:upper-roman}.mw-parser-output .reflist-lower-alpha{list-style-type:lower-alpha}.mw-parser-output .reflist-lower-greek{list-style-type:lower-greek}.mw-parser-output .reflist-lower-roman{list-style-type:lower-roman}
/* end https://en.wikipedia.org/ */
</style><div class="reflist">
<div class="mw-references-wrap mw-references-columns"><ol class="references">
<li id="cite_note-1"><span class="mw-cite-backlink"><b><a href="#cite_ref-1">^</a></b></span> <span class="reference-text"><style data-mw-deduplicate="TemplateStyles:r1238218222">
/* start https://en.wikipedia.org/ */
.mw-parser-output cite.citation{font-style:inherit;word-wrap:break-word}.mw-parser-output .citation q{quotes:"\"""\"""'""'"}.mw-parser-output .citation:target{background-color:rgba(0,127,255,0.133)}.mw-parser-output .id-lock-free.id-lock-free a{background:url("./mw/Lock-green.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-limited.id-lock-limited a,.mw-parser-output .id-lock-registration.id-lock-registration a{background:url("./mw/Lock-gray-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-subscription.id-lock-subscription a{background:url("./mw/Lock-red-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .cs1-ws-icon a{background:url("./mw/Wikisource-logo.svg")right 0.1em center/12px no-repeat}body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-free a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-limited a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-registration a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-subscription a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .cs1-ws-icon a{background-size:contain;padding:0 1em 0 0}.mw-parser-output .cs1-code{color:inherit;background:inherit;border:none;padding:inherit}.mw-parser-output .cs1-hidden-error{display:none;color:var(--color-error,#d33)}.mw-parser-output .cs1-visible-error{color:var(--color-error,#d33)}.mw-parser-output .cs1-maint{display:none;color:#085;margin-left:0.3em}.mw-parser-output .cs1-kern-left{padding-left:0.2em}.mw-parser-output .cs1-kern-right{padding-right:0.2em}.mw-parser-output .citation .mw-selflink{font-weight:inherit}@media screen{.mw-parser-output .cs1-format{font-size:95%}html.skin-theme-clientpref-night .mw-parser-output .cs1-maint{color:#18911f}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .cs1-maint{color:#18911f}}
/* end https://en.wikipedia.org/ */
</style><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://cwe.mitre.org/data/definitions/476.html">"CWE-476: NULL Pointer Dereference"</a>. <i>MITRE</i>.</cite></span>
</li>
<li id="cite_note-:0-2"><span class="mw-cite-backlink">^ <a href="#cite_ref-:0_2-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-:0_2-1"><sup><i><b>b</b></i></sup></a></span> <span class="reference-text"><cite id="CITEREFTony_Hoare2009" class="citation web cs1"><a href="Tony_Hoare" title="Tony Hoare">Tony Hoare</a> (2009-08-25). <a rel="nofollow" class="external text" href="http://www.infoq.com/presentations/Null-References-The-Billion-Dollar-Mistake-Tony-Hoare">"Null References: The Billion Dollar Mistake"</a>. InfoQ.com.</cite></span>
</li>
<li id="cite_note-3"><span class="mw-cite-backlink"><b><a href="#cite_ref-3">^</a></b></span> <span class="reference-text"><a href="#c-std">ISO/IEC 9899</a>, clause 6.3.2.3, paragraph 4.</span>
</li>
<li id="cite_note-4"><span class="mw-cite-backlink"><b><a href="#cite_ref-4">^</a></b></span> <span class="reference-text"><a href="#c-std">ISO/IEC 9899</a>, clause 7.17, paragraph 3: <i>NULL... which expands to an implementation-defined null pointer constant...</i></span>
</li>
<li id="cite_note-5"><span class="mw-cite-backlink"><b><a href="#cite_ref-5">^</a></b></span> <span class="reference-text"><a href="#c-std">ISO/IEC 9899</a>, clause 6.3.2.3, paragraph 3.</span>
</li>
<li id="cite_note-N3042-6"><span class="mw-cite-backlink"><b><a href="#cite_ref-N3042_6-0">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://open-std.org/JTC1/SC22/WG14/www/docs/n3042.htm">"WR14-N3042: Introduce the nullptr constant"</a>. <i>open-std.org</i>. 2022-07-22. <a rel="nofollow" class="external text" href="https://web.archive.org/web/20221224043228/https://open-std.org/JTC1/SC22/WG14/www/docs/n3042.htm">Archived</a> from the original on December 24, 2022.</cite></span>
</li>
<li id="cite_note-ub-7"><span class="mw-cite-backlink">^ <a href="#cite_ref-ub_7-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-ub_7-1"><sup><i><b>b</b></i></sup></a></span> <span class="reference-text"><a href="#c-std">ISO/IEC 9899</a>, clause 6.5.3.2, paragraph 4, esp. footnote 87.</span>
</li>
<li id="cite_note-8"><span class="mw-cite-backlink"><b><a href="#cite_ref-8">^</a></b></span> <span class="reference-text"><cite id="CITEREFLattner2011" class="citation web cs1">Lattner, Chris (2011-05-13). <a rel="nofollow" class="external text" href="https://blog.llvm.org/2011/05/what-every-c-programmer-should-know.html">"What Every C Programmer Should Know About Undefined Behavior #1/3"</a>. <i>blog.llvm.org</i>. <a rel="nofollow" class="external text" href="https://web.archive.org/web/20230614124121/https://blog.llvm.org/2011/05/what-every-c-programmer-should-know.html">Archived</a> from the original on 2023-06-14<span class="reference-accessdate">. Retrieved <span class="nowrap">2023-06-14</span></span>.</cite></span>
</li>
<li id="cite_note-9"><span class="mw-cite-backlink"><b><a href="#cite_ref-9">^</a></b></span> <span class="reference-text"><cite id="CITEREFStroustrup2001" class="citation book cs1"><a href="Bjarne_Stroustrup" title="Bjarne Stroustrup">Stroustrup, Bjarne</a> (March 2001). "Chapter 5: <br>The <code>const</code> qualifier (§5.4) prevents accidental redefinition of <code>NULL</code> and ensures that <code>NULL</code> can be used where a constant is required.". <i><a href="The_C%2B%2B_Programming_Language" title="The C++ Programming Language">The C++ Programming Language</a></i> (14th printing of 3rd ed.). United States and Canada: Addison–Wesley. p. <a rel="nofollow" class="external text" href="https://archive.org/details/cprogramminglang00stro_0/page/88">88</a>. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a> <bdi>0-201-88954-4</bdi>.</cite></span>
</li>
<li id="cite_note-10"><span class="mw-cite-backlink"><b><a href="#cite_ref-10">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://cwe.mitre.org/data/definitions/476.html">"CWE-476: NULL Pointer Dereference"</a>. <i>MITRE</i>.</cite></span>
</li>
<li id="cite_note-11"><span class="mw-cite-backlink"><b><a href="#cite_ref-11">^</a></b></span> <span class="reference-text"><i>The Objective-C 2.0 Programming Language</i>, <a rel="nofollow" class="external text" href="https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjectiveC/Chapters/ocObjectsClasses.html#//apple_ref/doc/uid/TP30001163-CH11-SW7">section "Sending Messages to nil"</a>.</span>
</li>
<li id="cite_note-12"><span class="mw-cite-backlink"><b><a href="#cite_ref-12">^</a></b></span> <span class="reference-text"><a rel="nofollow" class="external text" href="https://project-zero.issues.chromium.org/issues/42452311">"OS X exploitable kernel NULL pointer dereference in AppleGraphicsDeviceControl"</a></span>
</li>
<li id="cite_note-BondNethercote2007-13"><span class="mw-cite-backlink">^ <a href="#cite_ref-BondNethercote2007_13-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-BondNethercote2007_13-1"><sup><i><b>b</b></i></sup></a></span> <span class="reference-text"><cite id="CITEREFBondNethercoteKentGuyer2007" class="citation book cs1">Bond, Michael D.; Nethercote, Nicholas; Kent, Stephen W.; Guyer, Samuel Z.; McKinley, Kathryn S. (2007). "Tracking bad apples". <i>Proceedings of the 22nd annual ACM SIGPLAN conference on Object oriented programming systems and applications - OOPSLA '07</i>. p. 405. <a href="Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<a rel="nofollow" class="external text" href="https://doi.org/10.1145%2F1297027.1297057">10.1145/1297027.1297057</a>. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a> <bdi>9781595937865</bdi>. <a href="S2CID_(identifier)" class="mw-redirect" title="S2CID (identifier)">S2CID</a> <a rel="nofollow" class="external text" href="https://api.semanticscholar.org/CorpusID:2832749">2832749</a>.</cite></span>
</li>
<li id="cite_note-14"><span class="mw-cite-backlink"><b><a href="#cite_ref-14">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://www.eiffel.org/doc/eiffel/Void-safety-_Background%2C_definition%2C_and_tools">"Void-safety: Background, definition, and tools"</a><span class="reference-accessdate">. Retrieved <span class="nowrap">2021-11-24</span></span>.</cite></span>
</li>
<li id="cite_note-SafeD-15"><span class="mw-cite-backlink"><b><a href="#cite_ref-SafeD_15-0">^</a></b></span> <span class="reference-text"><cite id="CITEREFBartosz_Milewski" class="citation web cs1">Bartosz Milewski. <a rel="nofollow" class="external text" href="http://dlang.org/safed.html">"SafeD – D Programming Language"</a><span class="reference-accessdate">. Retrieved <span class="nowrap">17 July</span> 2014</span>.</cite></span>
</li>
<li id="cite_note-16"><span class="mw-cite-backlink"><b><a href="#cite_ref-16">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://hacks.mozilla.org/2019/01/fearless-security-memory-safety/">"Fearless Security: Memory Safety"</a>. <a rel="nofollow" class="external text" href="https://web.archive.org/web/20201108003116/https://hacks.mozilla.org/2019/01/fearless-security-memory-safety/">Archived</a> from the original on 8 November 2020<span class="reference-accessdate">. Retrieved <span class="nowrap">4 November</span> 2020</span>.</cite></span>
</li>
<li id="cite_note-17"><span class="mw-cite-backlink"><b><a href="#cite_ref-17">^</a></b></span> <span class="reference-text"><cite id="CITEREFTony_Hoare2009" class="citation web cs1"><a href="Tony_Hoare" title="Tony Hoare">Tony Hoare</a> (2009-08-25). <a rel="nofollow" class="external text" href="https://qconlondon.com/london-2009/qconlondon.com/london-2009/presentation/Null%2BReferences_%2BThe%2BBillion%2BDollar%2BMistake.html">"Presentation: "Null References: The Billion Dollar Mistake""</a>. InfoQ.com.</cite></span>
</li>
<li id="cite_note-18"><span class="mw-cite-backlink"><b><a href="#cite_ref-18">^</a></b></span> <span class="reference-text"><cite id="CITEREFContieri2025" class="citation web cs1">Contieri, Maxi (2025-06-18). <a rel="nofollow" class="external text" href="https://maximilianocontieri.com/code-smell-304-null-pointer-exception">"Code Smell 304 - Null Pointer Exception"</a>. <i>Maximiliano Contieri - Software Design</i><span class="reference-accessdate">. Retrieved <span class="nowrap">2025-06-18</span></span>.</cite></span>
</li>
</ol></div></div>
<div class="mw-heading mw-heading2"><h2 id="References">References</h2></div>
<style data-mw-deduplicate="TemplateStyles:r1239549316">
/* start https://en.wikipedia.org/ */
.mw-parser-output .refbegin{margin-bottom:0.5em}.mw-parser-output .refbegin-hanging-indents>ul{margin-left:0}.mw-parser-output .refbegin-hanging-indents>ul>li{margin-left:0;padding-left:3.2em;text-indent:-3.2em}.mw-parser-output .refbegin-hanging-indents ul,.mw-parser-output .refbegin-hanging-indents ul li{list-style:none}@media(max-width:720px){.mw-parser-output .refbegin-hanging-indents>ul>li{padding-left:1.6em;text-indent:-1.6em}}.mw-parser-output .refbegin-columns{margin-top:0.3em}.mw-parser-output .refbegin-columns ul{margin-top:0}.mw-parser-output .refbegin-columns li{page-break-inside:avoid;break-inside:avoid-column}@media screen{.mw-parser-output .refbegin{font-size:90%}}
/* end https://en.wikipedia.org/ */
</style><div class="refbegin" style="">
<ul><li><cite id="c-std" class="citation book cs1">Joint Technical Committee ISO/IEC JTC 1, Subcommittee SC 22, Working Group WG 14 (2007-09-08). <a rel="nofollow" class="external text" href="http://www.open-std.org/jtc1/sc22/WG14/www/docs/n1256.pdf"><i>International Standard ISO/IEC 9899</i></a> <span class="cs1-format">(PDF)</span> (Committee Draft).</cite><span class="cs1-maint citation-comment"><code class="cs1-code">{{cite book}}</code>: CS1 maint: multiple names: authors list (link) CS1 maint: numeric names: authors list (link)</span></li></ul>
</div>
<div class="navbox-styles"><style data-mw-deduplicate="TemplateStyles:r1129693374">
/* start https://en.wikipedia.org/ */
.mw-parser-output .hlist dl,.mw-parser-output .hlist ol,.mw-parser-output .hlist ul{margin:0;padding:0}.mw-parser-output .hlist dd,.mw-parser-output .hlist dt,.mw-parser-output .hlist li{margin:0;display:inline}.mw-parser-output .hlist.inline,.mw-parser-output .hlist.inline dl,.mw-parser-output .hlist.inline ol,.mw-parser-output .hlist.inline ul,.mw-parser-output .hlist dl dl,.mw-parser-output .hlist dl ol,.mw-parser-output .hlist dl ul,.mw-parser-output .hlist ol dl,.mw-parser-output .hlist ol ol,.mw-parser-output .hlist ol ul,.mw-parser-output .hlist ul dl,.mw-parser-output .hlist ul ol,.mw-parser-output .hlist ul ul{display:inline}.mw-parser-output .hlist .mw-empty-li{display:none}.mw-parser-output .hlist dt::after{content:": "}.mw-parser-output .hlist dd::after,.mw-parser-output .hlist li::after{content:" · ";font-weight:bold}.mw-parser-output .hlist dd:last-child::after,.mw-parser-output .hlist dt:last-child::after,.mw-parser-output .hlist li:last-child::after{content:none}.mw-parser-output .hlist dd dd:first-child::before,.mw-parser-output .hlist dd dt:first-child::before,.mw-parser-output .hlist dd li:first-child::before,.mw-parser-output .hlist dt dd:first-child::before,.mw-parser-output .hlist dt dt:first-child::before,.mw-parser-output .hlist dt li:first-child::before,.mw-parser-output .hlist li dd:first-child::before,.mw-parser-output .hlist li dt:first-child::before,.mw-parser-output .hlist li li:first-child::before{content:" (";font-weight:normal}.mw-parser-output .hlist dd dd:last-child::after,.mw-parser-output .hlist dd dt:last-child::after,.mw-parser-output .hlist dd li:last-child::after,.mw-parser-output .hlist dt dd:last-child::after,.mw-parser-output .hlist dt dt:last-child::after,.mw-parser-output .hlist dt li:last-child::after,.mw-parser-output .hlist li dd:last-child::after,.mw-parser-output .hlist li dt:last-child::after,.mw-parser-output .hlist li li:last-child::after{content:")";font-weight:normal}.mw-parser-output .hlist ol{counter-reset:listitem}.mw-parser-output .hlist ol>li{counter-increment:listitem}.mw-parser-output .hlist ol>li::before{content:" "counter(listitem)"\a0 "}.mw-parser-output .hlist dd ol>li:first-child::before,.mw-parser-output .hlist dt ol>li:first-child::before,.mw-parser-output .hlist li ol>li:first-child::before{content:" ("counter(listitem)"\a0 "}
/* end https://en.wikipedia.org/ */
</style><style data-mw-deduplicate="TemplateStyles:r1236075235">
/* start https://en.wikipedia.org/ */
.mw-parser-output .navbox{box-sizing:border-box;border:1px solid #a2a9b1;width:100%;clear:both;font-size:88%;text-align:center;padding:1px;margin:1em auto 0}.mw-parser-output .navbox .navbox{margin-top:0}.mw-parser-output .navbox+.navbox,.mw-parser-output .navbox+.navbox-styles+.navbox{margin-top:-1px}.mw-parser-output .navbox-inner,.mw-parser-output .navbox-subgroup{width:100%}.mw-parser-output .navbox-group,.mw-parser-output .navbox-title,.mw-parser-output .navbox-abovebelow{padding:0.25em 1em;line-height:1.5em;text-align:center}.mw-parser-output .navbox-group{white-space:nowrap;text-align:right}.mw-parser-output .navbox,.mw-parser-output .navbox-subgroup{background-color:#fdfdfd}.mw-parser-output .navbox-list{line-height:1.5em;border-color:#fdfdfd}.mw-parser-output .navbox-list-with-group{text-align:left;border-left-width:2px;border-left-style:solid}.mw-parser-output tr+tr>.navbox-abovebelow,.mw-parser-output tr+tr>.navbox-group,.mw-parser-output tr+tr>.navbox-image,.mw-parser-output tr+tr>.navbox-list{border-top:2px solid #fdfdfd}.mw-parser-output .navbox-title{background-color:#ccf}.mw-parser-output .navbox-abovebelow,.mw-parser-output .navbox-group,.mw-parser-output .navbox-subgroup .navbox-title{background-color:#ddf}.mw-parser-output .navbox-subgroup .navbox-group,.mw-parser-output .navbox-subgroup .navbox-abovebelow{background-color:#e6e6ff}.mw-parser-output .navbox-even{background-color:#f7f7f7}.mw-parser-output .navbox-odd{background-color:transparent}.mw-parser-output .navbox .hlist td dl,.mw-parser-output .navbox .hlist td ol,.mw-parser-output .navbox .hlist td ul,.mw-parser-output .navbox td.hlist dl,.mw-parser-output .navbox td.hlist ol,.mw-parser-output .navbox td.hlist ul{padding:0.125em 0}.mw-parser-output .navbox .navbar{display:block;font-size:100%}.mw-parser-output .navbox-title .navbar{float:left;text-align:left;margin-right:0.5em}body.skin--responsive .mw-parser-output .navbox-image img{max-width:none!important}@media print{body.ns-0 .mw-parser-output .navbox{display:none!important}}
/* end https://en.wikipedia.org/ */
</style></div><div role="navigation" class="navbox" aria-labelledby="Nulls_in_computing108" style="padding:3px"><table class="nowraplinks mw-collapsible autocollapse navbox-inner" style="border-spacing:0;background:transparent;color:inherit"><tbody><tr><th scope="col" class="navbox-title" colspan="2"><style data-mw-deduplicate="TemplateStyles:r1239400231">
/* start https://en.wikipedia.org/ */
.mw-parser-output .navbar{display:inline;font-size:88%;font-weight:normal}.mw-parser-output .navbar-collapse{float:left;text-align:left}.mw-parser-output .navbar-boxtext{word-spacing:0}.mw-parser-output .navbar ul{display:inline-block;white-space:nowrap;line-height:inherit}.mw-parser-output .navbar-brackets::before{margin-right:-0.125em;content:"[ "}.mw-parser-output .navbar-brackets::after{margin-left:-0.125em;content:" ]"}.mw-parser-output .navbar li{word-spacing:-0.125em}.mw-parser-output .navbar a>span,.mw-parser-output .navbar a>abbr{text-decoration:inherit}.mw-parser-output .navbar-mini abbr{font-variant:small-caps;border-bottom:none;text-decoration:none;cursor:inherit}.mw-parser-output .navbar-ct-full{font-size:114%;margin:0 7em}.mw-parser-output .navbar-ct-mini{font-size:114%;margin:0 4em}html.skin-theme-clientpref-night .mw-parser-output .navbar li a abbr{color:var(--color-base)!important}@media(prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .navbar li a abbr{color:var(--color-base)!important}}@media print{.mw-parser-output .navbar{display:none!important}}
/* end https://en.wikipedia.org/ */
</style><div id="Nulls_in_computing108" style="font-size:114%;margin:0 4em">Nulls in <a href="Computing" title="Computing">computing</a></div></th></tr><tr><td colspan="2" class="navbox-list navbox-odd hlist" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul><li><a href="Null_character" title="Null character">Null character</a></li>
<li><a href="Null_device" title="Null device">Null device</a></li>
<li><a href="Null_function" title="Null function">Null function</a></li>
<li><a href="Null_modem" title="Null modem">Null modem</a></li>
<li><a href="Null_object_pattern" title="Null object pattern">Null object pattern</a></li>
<li><a href="Null_(SQL)" title="Null (SQL)">Null in SQL</a></li>
<li><a href="Empty_string" title="Empty string">Null string</a></li>
<li><a href="Null_coalescing_operator" title="Null coalescing operator">Null coalescing operator</a></li></ul>
</div></td></tr><tr><td class="navbox-abovebelow hlist" colspan="2"><div>
<ul><li><i>See also:</i> <a href="Null_coalescing_operator" title="Null coalescing operator">Null coalescing operator</a></li>
<li><a href="Nullable_type" title="Nullable type">Nullable type</a></li>
<li><a href="Undefined_value" title="Undefined value">Undefined value</a></li></ul>
</div></td></tr></tbody></table></div></div><!--htdig_noindex--><div><div class="zim-footer">
This article is issued from <a class="external text" title="Last edited on 2025-07-20" href="https://en.wikipedia.org/wiki/?title=Null_pointer&oldid=1301482385">Wikipedia</a>. The text is available under <a class="external text" href="https://creativecommons.org/licenses/by-sa/4.0/deed.en">Creative Commons Attribution-Share Alike 4.0</a> unless otherwise noted. Additional terms may apply for the media files.
</div>
</div><!--/htdig_noindex--></div>
</div>
</main>
</div>
</div>
</div>
</body></html>